package com.immo.libcommon.base;

import com.immo.libcommon.http.BaseBean;

import android.os.Parcel;
import android.os.Parcelable;

import java.io.Serializable;

/**
 * @author Administrator
 * @content 登录的Bean
 * @date 2017/12/2
 */

public class LoginBean extends BaseBean implements Parcelable,Serializable{


    /**
     * success : true
     * message : Successfully login user18856496491
     * payload : {"token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6ImM2OGRmY2EyLTZmNGEtNGY0ZS04ODBmLTZlMGEzNzQ2NGZmOSIsInVzZXJuYW1lIjoiMTg4NTY0OTY0OTEiLCJyb2xlIjoidXNlciIsImV4cCI6MTUzMTIxNDU3MCwiaWF0IjoxNTMxMjA0NDkwfQ.5UOcslDMWakUiwdrPOT4gHUyudbQ_xqAnyWv4AbdEbI"}
     */

    private boolean success;
    private String message;
    private PayloadBean payload;

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public PayloadBean getPayload() {
        return payload;
    }

    public void setPayload(PayloadBean payload) {
        this.payload = payload;
    }

    public static class PayloadBean implements Parcelable,Serializable {
        /**
         * token : eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6ImM2OGRmY2EyLTZmNGEtNGY0ZS04ODBmLTZlMGEzNzQ2NGZmOSIsInVzZXJuYW1lIjoiMTg4NTY0OTY0OTEiLCJyb2xlIjoidXNlciIsImV4cCI6MTUzMTIxNDU3MCwiaWF0IjoxNTMxMjA0NDkwfQ.5UOcslDMWakUiwdrPOT4gHUyudbQ_xqAnyWv4AbdEbI
         */

        private String token;
        public String getUsername() {
            return username == null ? "" : username;
        }

        public void setUsername(String username) {
            this.username = username;
        }

        private String username;

        public String getToken() {
            return token==null?"":token;
        }

        public void setToken(String token) {
            this.token = token;
        }

        @Override
        public int describeContents() {
            return 0;
        }

        @Override
        public void writeToParcel(Parcel dest, int flags) {
            dest.writeString(this.token);
            dest.writeString(this.username);
        }

        public PayloadBean() {
        }

        protected PayloadBean(Parcel in) {
            this.token = in.readString();
            this.username=in.readString();
        }

        public static final Creator<PayloadBean> CREATOR = new Creator<PayloadBean>() {
            @Override
            public PayloadBean createFromParcel(Parcel source) {
                return new PayloadBean(source);
            }

            @Override
            public PayloadBean[] newArray(int size) {
                return new PayloadBean[size];
            }
        };
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeByte(this.success ? (byte) 1 : (byte) 0);
        dest.writeString(this.message);
        dest.writeParcelable(this.payload, flags);
    }

    public LoginBean() {
    }

    protected LoginBean(Parcel in) {
        this.success = in.readByte() != 0;
        this.message = in.readString();
        this.payload = in.readParcelable(PayloadBean.class.getClassLoader());
    }

    public static final Creator<LoginBean> CREATOR = new Creator<LoginBean>() {
        @Override
        public LoginBean createFromParcel(Parcel source) {
            return new LoginBean(source);
        }

        @Override
        public LoginBean[] newArray(int size) {
            return new LoginBean[size];
        }
    };
}
